
import { _decorator, Component, Node, game, Vec3, v3 } from 'cc';
import { BarrierGroup } from './BarrierGroup';
import { Role } from './Role';
import GameConfig from '../../Script/GameSpecial/GameConfig';
import GameData from '../../Script/Common/GameData';
import { GlobalEnum } from '../../Script/GameSpecial/GlobalEnum';
const { ccclass, property } = _decorator;
/**中间的墙壁 */
@ccclass('WallBarrierGroup')
export class WallBarrierGroup extends BarrierGroup {

    protected setData(data: { z: number, r: number }) {
        this.node.setPosition(0, 0, data.z);
        this.radianZ = data.r;
        let r = data.r * 0.5;
        this.node.setRotation(0, 0, Math.sin(r), Math.cos(r));
        let collData = GameData.getData(GlobalEnum.GameDataType.CollItemData, this.node.name);
        this.width = collData.width;
        this.houDu = collData.houDu;
        r = this.width * 0.5 / GameConfig.GameRule.roadHalfWidth;
        this.minRadian = this.radianZ - r;
        this.maxRadian = this.radianZ + r;
        this.minZ = data.z - this.houDu * 0.5;
        this.maxZ = this.minZ + this.houDu;
    }

    public checkColl(role: Role) {
        if (role.minRadian <= this.maxRadian && role.maxRadian >= this.minRadian) {
            return true;
        }
        let w = (this.width + role.width) * 0.5;
        let r = w / (GameConfig.GameRule.roadHalfWidth - role.height);
        return r > Math.abs(this.radianZ - role.radianZ);
    }

    protected getChildWorldPos(node: Node, p: Vec3) {
        node.getPosition(p);
        p.x = -p.y * Math.sin(this.radianZ);
        p.y *= Math.cos(this.radianZ);
        p.z = this.z;
        return p;
    }

    protected radianZ;
    protected width: number;
    protected houDu: number;
}
